package com.yanqu.road.server.cmd.clinic;

import com.yanqu.road.pb.clinic.ClinicProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.clinic.ClinicModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/3/3 11:40
 */
@Cmd(code = GameProtocol.S_CLINIC_UPGRADE_DEPARTMENT, desc = "科室升级")
public class UpgradeDepartmentCmd extends AbstractCommand {
    private int type;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ClinicProto.UpgradeDepartmentReqMsg msg = ClinicProto.UpgradeDepartmentReqMsg.parseFrom(packet.getBytes());
        type = msg.getType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(ClinicModule.class).departmentUpgrade(type);
    }

    @Override
    public void sendData(GamePlayer player) {
        ClinicProto.UpgradeDepartmentRespMsg.Builder respMsg = ClinicProto.UpgradeDepartmentRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_CLINIC_UPGRADE_DEPARTMENT, respMsg);
    }
}
